<?php
/*
	积分排行
*/
defined('BY_JYA') or exit('error');
$this->model('member')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	//获取会员总积分、会员本周获得总积分
	$item=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('credit1','nickname','avatar'));
	$week_start_time=strtotime(date('Y-m-d', strtotime("this week Monday", TIMESTAMP)));
	$logs=pdo_getall('core_credit_log',array('mid'=>$_SESSION['uid'],'type'=>1,'createtime >'=>$week_start_time),array('is_add','fee'));
	$week_change=0.00;
	foreach($logs as $log){
		if($log['is_add']){
			$week_change+=$log['fee'];
		}else{
			$week_change-=$log['fee'];
		}
	}
	$item['week_credit']=$week_change;
	$count=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'credit1 >'=>$item['credit1']));
	$item['rank']=$count+1;
	$return['item']=$item;
	set_html('title','积分排行榜');
	exi($return);
}
if($_RQ['op']=='order_rank'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	//获取会员总积分、会员本周获得总积分
	$item=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('credit1','nickname','avatar'));
	$week_start_time=strtotime(date('Y-m-d', strtotime("this week Monday", TIMESTAMP)));
	$price=pdo_getsum('jy_weishop_order',array('mid'=>$_SESSION['uid'],'ispay'=>1,'createtime >'=>$week_start_time),'price');
	$item['week_credit']=$price;
	$count=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'credit1 >'=>$item['credit1']));
	$item['rank']=$count+1;
	$return['item']=$item;
	set_html('title','消费排行榜');
	exi($return);
}
// 获取排名数据
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['list']=pdo_getslice('core_members',$params,array($pindex,$psize),$total,array('id','credit1','nickname','avatar'),'','credit1 desc');
	exi($return);
}
// 获取消费排名数据
if($_RQ['op']=='getorderlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['list']=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,array('id','price','mid'));
	exi($return);
}
?>